package com.zyht.wechat;
import javax.annotation.Resource;

import com.zyht.redis.service.RedisService;

/**
 * <b>描述：如果是集群请使用RedisLockAccessTokenVisitorImpl</b>	<br/>
 * <b>作者：</b>Bob <br/>
 * <b>修改日期：</b>2017年6月26日 - 下午3:10:13<br/>
 *	@see com.zyht.wechat.RedisLockAccessTokenVisitorImpl
 */
public class RedisAccessTokenVistor implements AccessTokenService {

	@Resource
	private RedisService redisService;

	@Override
	public String getTokenSequence(String key) {
		return this.redisService.get(createRedisKey(key));
	}

	@Override
	public void persist(String key, AccessToken accessToken) {
		if (null == accessToken)
			throw new NullPointerException("非法的AccessToken对象");
		this.redisService.setEx(createRedisKey(key), accessToken.getExpiresIn().longValue() - 6700,
				accessToken.getAccessToken());
	}

	private final String createRedisKey(String key) {
		return "com.zyht.wechat.AccessToken.".concat(key);
	}
}
